//
//  SettingMoneyViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/27.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "NewChongZhiViewController.h"
#import "JTCSM.h"
#import "GetInfoClass.h"
#import "My_KeyBoardView.h"
#import "MyInfoView.h"
#import "PayBankCarListViewController.h"
#import "NewTongDaoViewController.h"
static CGFloat viewHeight = 60;
static CGFloat space = 20;
static CGFloat labelheight = 55;
@interface NewChongZhiViewController ()<UITextFieldDelegate,PayBankCarListViewControllerDelegate,My_KeyBoardDelegate>
{
    UILabel *mylabel;
    NSString *phone;
    NSString *type;
}
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UIImageView *statusImageView;
@property (nonatomic,strong) UITextField *textfield;
@property (nonatomic,strong) My_KeyBoardView *my_keyboard;
@property (nonatomic,strong) UIView *secondView;
@property (nonatomic,strong) MyInfoView *infoView;


@end

@implementation NewChongZhiViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    type = @"";

    [self layoutOtherView];
    [self layoutHeaderView];
    
    [self keyBoardTypeAction];
}
- (void)keyBoardTypeAction {
    
    self.my_keyboard = [[My_KeyBoardView alloc] initWithNumber:@2];
    
    self.my_keyboard.delegate = self;
    [self.view addSubview:self.my_keyboard];
}
#pragma mark My_KeyBoardViewDelegate
- (void)numberKeyBoard:(NSInteger)number
{
    NSString *str = self.textfield.text;
    if ([self.textfield.text rangeOfString:@"."].location == NSNotFound) {
        if ([str isEqualToString:@""] || str==nil) {
            if (number == 0) {
                self.textfield.text = [NSString stringWithFormat:@"%@%ld.",str,(long)number];
            }else{
                self.textfield.text = [NSString stringWithFormat:@"%@%ld",str,(long)number];
            }
        }else{
            self.textfield.text = [NSString stringWithFormat:@"%@%ld",str,(long)number];
        }
    }else{
        NSRange range = [str rangeOfString:@"."];
        if (str.length >=range.location+3) {
            return;
        }else{
            self.textfield.text = [NSString stringWithFormat:@"%@%ld",str,(long)number];
        }
        
    }
    
    
    
}
- (void)doubleNumberKeyBoard{
    NSString *str = self.textfield.text;
    
    if ([self.textfield.text rangeOfString:@"."].location == NSNotFound) {
        if ([str isEqualToString:@""] || str==nil) {
            
            return;
        }else{
            self.textfield.text = [NSString stringWithFormat:@"%@00",str];
        }
    }else{
        NSRange range = [str rangeOfString:@"."];
        self.textfield.text = [NSString stringWithFormat:@"%@00",str];
        if (self.textfield.text.length >range.location+3) {
            self.textfield.text = [self.textfield.text stringByReplacingCharactersInRange:NSMakeRange(range.location+3, self.textfield.text.length-(range.location+3)) withString:@""];
        }
    }
}
- (void)cancelKeyBoard{
    
    NSMutableString *muStr = [[NSMutableString alloc] initWithString:self.textfield.text];
    if (muStr.length <= 0) {
        return;
    }
    [muStr deleteCharactersInRange:NSMakeRange([muStr length] - 1, 1)];
    self.textfield.text = muStr;
}

- (void)removeAllData{
    self.textfield.text = @"";
}
- (void)finishKeyBoard{
    
//    [self gotoMainV];
    [self gotoTongDaoVC];
}
- (void)gotoTongDaoVC {
    NewTongDaoViewController *vc = [[NewTongDaoViewController alloc]init];
    vc.nameTitle = @"选择支付通道";
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma 输入点
-(void)periodKeyBoard{
    if ([self.textfield.text isEqualToString:@""]) {
        self.textfield.text=@"0.";
        return;
    }
    
    //判断当前时候存在一个点
    if ([self.textfield.text rangeOfString:@"."].location == NSNotFound) {
        //输入中没有点
        NSMutableString  *mutableString=[[NSMutableString alloc]initWithFormat:@"%@%@",self.textfield.text,@"."];
        self.textfield.text=mutableString;
    }
}


- (void)layoutOtherView{
    
    
    
    
    CGFloat changeHeight = 18;
    
    CGFloat LabelHeight = 120;
    
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, KagainChangeHeight, KCONTROLLERWith, LabelHeight+changeHeight*2)];
    backview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backview];
    backview.userInteractionEnabled = YES;
    
    NSString *title = @"¥";
    CGFloat font = 36;
    
    CGRect rect = [df labelHeightWithContent:title height:LabelHeight font:font];
    
    UILabel *label = [UILabel initWithFrame:CGRectMake(space, KagainChangeHeight+4+changeHeight+(LabelHeight-rect.size.height)/2, rect.size.width, rect.size.height) text:title font:font textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
    [self.view addSubview:label];
    
    
    self.textfield = [UITextField initWithframe:CGRectMake(KVIEW_X(label)+5, KagainChangeHeight+changeHeight+5, KCONTROLLERWith-KVIEW_X(label)-space-5, LabelHeight) backgrandColor:nil placeholder:@"输入金额" textAlignment:NSTextAlignmentLeft font:font texcolor:RGBACOLOR(52, 52, 52, 1)];
    self.textfield.enabled = NO;
    [self.view addSubview:self.textfield];
    
    [df lineViewWithHeightofTop:KVIEW_Y(self.textfield)+10 superView:self.view spacing:space color:RGBACOLOR(241, 241, 241, 1) lineHeight:2];
    
    
}


- (void)layoutHeaderView{

    CGFloat top = 0;
    [df lineViewWithHeightofTop:top superView:self.view spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:top];
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(_textfield)+10, KCONTROLLERWith, viewHeight)];
    backview.userInteractionEnabled = YES;
    backview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backview];

    CGFloat namelableWidth = 300;
    self.nameLabel = [UILabel initWithFrame:CGRectMake(space, top*2, namelableWidth, viewHeight) text:@"选择银行卡" font:14 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"999999" alpha:1] backgroundColor:nil];
    [backview addSubview:self.nameLabel];
    self.nameLabel.userInteractionEnabled = YES;
    
    CGRect rect1 = [df labelHeightWithContent:@"更多" width:1000 font:15];
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(KCONTROLLERWith-space-rect1.size.width, (viewHeight-rect1.size.height-2)/2, rect1.size.width, rect1.size.height+2) text:@"更多" font:15 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"ff3636" alpha:1] backgroundColor:nil];
    [backview addSubview:titleLabel];
    titleLabel.userInteractionEnabled = YES;
    [df newlineViewWithHeightofTop:rect1.size.height+1 superView:titleLabel spacing:0 color:[df colorWithHexString:@"ff3636" alpha:1] lineHeight:1];
    [df addTapGestureRecognizerWithTarget:self action:@selector(gotobankList) andaddView:backview];
    
    
    
    [df lineViewWithHeightofTop:KVIEW_Y(backview)+6 superView:self.view spacing:space color:RGBACOLOR(241, 241, 241, 1) lineHeight:2];
    
    
    _secondView = [[UIView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(backview)+10, (KCONTROLLERWith-0), labelheight)];
    _secondView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_secondView];
    [df layerWithView:_secondView radius:5 width:0 color:nil];
    CGFloat headerImagesize = 15;
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, (labelheight-headerImagesize)/2, headerImagesize, headerImagesize)];
    imageView.image = [UIImage imageNamed:@"设置金额_注.png"];
    [_secondView addSubview:imageView];
    UILabel *label = [UILabel initWithFrame:CGRectMake(KVIEW_X(imageView)+10 , 0, KCONTROLLERWith-(KVIEW_X(imageView)+30), labelheight) text:@"结算费费率0.50%，早8:00--晚21:00交易当日结算，其他时间次日结算" font:12 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:nil];
    label.numberOfLines = 2;
    [_secondView addSubview:label];
    
}

- (void)gotoMainV{
    
    
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"UserReceive/create") withDict:@{@"token":KTokenString,@"encrypt":self.encrypt,@"type":type,@"total_price":self.textfield.text} superView:nil isAddtag:YES Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        
        if ([isreturn isEqualToString:@"1"]) {
            
            NSDictionary *dict = KResultOfKey(@"data");
            
            
            [self.delegate getMoney:[dict objectForKey:@"total_price"] erweima:[dict objectForKey:@"qrcode"] backImage:[dict objectForKey:@"poster"]];
            [self gotBack];
            
        }
    }];
    
    
}


- (void)gotobankList{
    PayBankCarListViewController *vc = [[PayBankCarListViewController alloc]init];
    vc.nameTitle = @"银行卡";
    vc.delegate = self;
    vc.isbanklist = NO;
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark 选择银行卡代理方法
- (void)getBankInfo:(MyBankCardModel*)model;{
    NSString *bank_id = [model.bank_card substringWithRange:NSMakeRange(model.bank_card.length-4, 4)];
    self.nameLabel.text = [NSString stringWithFormat:@"%@（%@）",model.bank_name,bank_id];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

